/*
 * Attempt to solve the "Timber Auction" problem.
 */

#include "stdafx.h"
using namespace std;

void timber_auction_main()  {
	int rows, cols;
	cin >> rows >> cols;

	typedef vector<int> intvector;
	vector<intvector> matrix(rows+1);

	for(int i = 0; i < rows+1; i++)
		matrix[i].resize(cols+1);
	for(int i = 0; i < rows+1; i++) matrix[i][0] = 0;
	for(int i = 0; i < cols+1; i++) matrix[0][i] = 0;

	for(int i = 1; i <= rows; i++)  {
		for(int j = 1; j <= cols; j++)  {
			cin >> matrix[i][j];
			matrix[i][j] += matrix[i-1][j] + matrix[i][j-1] - matrix[i-1][j-1];
		}
	}

	int ntests; cin >> ntests;
	for(int i = 0; i < ntests; i++)  {
		int r1, r2, c1, c2;
		cin >> r1 >> c1 >> r2 >> c2;

		int area = matrix[r2][c2] + matrix[r1-1][c1-1] - matrix[r1-1][c2] - matrix[r2][c1-1];
		cout << area << endl;
	}
}